package com.yc.jpyy.facecheck.controller;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.config.Config;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;


@Controller
@RequestMapping(value = "/facecheck")
public class StudentFaceCheckController extends BaseController{
	
	private static Logger logger = LoggerFactory.getLogger(StudentFaceCheckController.class);	
	
	@Autowired
	private BizService bizService;

	@Autowired
	private BizDao bizDao;
	
	/**
	 *根据身份证编号获取学员基本信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/GetStudentInfo", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody String GetStudentInfo(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");
		try {
			// 身份证编号
			String IdCardNum = request.getParameter("IdCardNum");	
			if(IdCardNum != null && !IdCardNum.isEmpty()){
				String imgUrl = Config.getImageAddress();
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("imgUrl", imgUrl);
				valMap.put("IdCardNum", IdCardNum);
				List<Map<String, Object>> stumap = bizService.getStudentInfoForTerminater(valMap);
				if (stumap != null && stumap.size() > 0) {
					response.setData(stumap);
				}else {
					response.setErrorcode(1);
					response.setMessage("该学员无基本信息...");
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("身份证编号不能为空...");
			}	
		} catch (Exception e) {
			logger.info("GetStudentInfo:"+ e.toString());
			response.setReturnMsg(1,"学员基本信息获取失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/**
	 *根据学员全国编号获取学员基本信息（通过扫二维码登陆以后调此接口获取信息）
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/GetStudentInfoByNum", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody String GetStudentInfoByNum(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");
		
		try {
			// 学员全国编号
			String Stunum = request.getParameter("Stunum");	
			if(Stunum != null && !Stunum.isEmpty()){
				String imgUrl = Config.getImageAddress();
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("imgUrl", imgUrl);
				valMap.put("Stunum", Stunum);
				List<Map<String, Object>> stumap = bizService.getStudentInfoForTerminater(valMap);
				if (stumap != null && stumap.size() > 0) {
					response.setData(stumap);
				}else {
					response.setErrorcode(1);
					response.setMessage("该学员无基本信息...");
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("学员全国编号不能为空...");
			}		
		} catch (Exception e) {
			logger.info("GetStudentInfoByNum:"+ e.toString());
			response.setReturnMsg(1,"学员基本信息获取失败！");
		} finally {
			return response.toJSON();
		}
	}
	
}
